package components;

import java.io.IOException;
import java.util.concurrent.Semaphore;
import javax.swing.JComponent;

import client.WarChoosePieceComponent;
import client.WarShowFightAnimation;
import enums.Weapon;
import utils.Piece;

/**
 * set glasspane at the correct size
 * 
 *
 */
public class RPSGlassPane extends JComponent {

	private static final long serialVersionUID = 1L;
	
//	public static final String WAR_CHOOSE = "WarChoose";
	
	public Object returnedFromPanel = null;
	
	public RPSGlassPane () {
		setOpaque(false);
		setLayout(null);
	}
	
	public Weapon showWarChoosePieceComponent(Semaphore s) {
		removeAll();
		
		WarChoosePieceComponent war = new WarChoosePieceComponent();
		Weapon weapon = Weapon.NONE ;
		try {
			add(war);
			war.createPanel(s , this);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		setPaneVisible(true);
		return weapon;
	}
	
	public void showWarAnimation(Piece me , Piece enemy, Semaphore s) {
		removeAll();
		
		try {
			WarShowFightAnimation warShowFightAnimation = new WarShowFightAnimation(me , enemy);
			
			add(warShowFightAnimation);
			warShowFightAnimation.startAnimation(s);
			
			setPaneVisible(true);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void showMessagePanel (String str) {
		removeAll();
		
		MessageToPlayer mtp = new MessageToPlayer(str);
		add(mtp);
		mtp.showMessage();
		getRootPane().getGlassPane().setSize(mtp.getSize());
		setPaneVisible(true);
	}


	
	public void setPaneVisible (boolean isVisible) {
		getRootPane().getGlassPane().setVisible(isVisible);
	}
	
	public Object getReturnedFromPanel () {
		return returnedFromPanel;
	}
}	
